<?php

class Model_Cartrige extends CLib_Model
{
	public function __construct($id = null)
	{
		parent::__construct(new Model_DbTable_Cartriges, $id);
	}

	public function getAllCartriges()
	{
		return $this->_dbTable->fetchAll();
	}
	
	public function populateForm()
	{
		return $this->_row->toArray();
	}	
	
	public function getAllCartrigesByGroup($group)
	{
		$db = Zend_Db_Table::getDefaultAdapter();
		$select = $this->_dbTable->select()->group($group);
		$result = $db->fetchAll($select, null, Zend_Db::FETCH_OBJ);
		foreach ($result as $item)
		{			
			$select = $this->_dbTable->select()
				->from($this->_dbTable, 'COUNT(*) as count')
				->where("name = '$item->name'");
			$allcount = $db->fetchRow($select, null, Zend_Db::FETCH_OBJ);			
			$item->count = $allcount->count;
			
			$select = $select->where("`isempty` != 1 and `inprocess` != 1");
			$fullcount = $db->fetchRow($select, null, Zend_Db::FETCH_OBJ);			
			$item->full = $fullcount->count;
		}		
		return $result;
	}
	
	public function getAllCartrigesByModel($modelname)
	{
		$db = Zend_Db_Table::getDefaultAdapter();
		$select = $this->_dbTable->select()->where("name = '$modelname'");
		return $db->fetchAll($select, null, Zend_Db::FETCH_OBJ);				
	}
	
	public function getStatistic()
	{
		/*
		$db = Zend_Db_Table::getDefaultAdapter();
		$select = $this->_dbTable->select();
		return $db->fetchAll($select, null, Zend_Db::FETCH_OBJ);
		*/
	}
	
	
}

